/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.bme.j2ee.v37zen.web.beans;

import hu.bme.j2ee.v37zen.beans.AdministratorBean;
import hu.bme.j2ee.v37zen.beans.FindUsersBean;
import hu.bme.j2ee.v37zen.beans.LoginBean;
import hu.bme.j2ee.v37zen.entities.User;
import java.io.Serializable;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Kiss Dániel
 */
@ManagedBean
@ViewScoped
@RolesAllowed("ADMIN")
public class AdminManagedBean implements Serializable{
    private static final long serialVersionUID = 1166819166780806977L;
 
    @EJB
    AdministratorBean ab;
    @EJB
    LoginBean lb;

    /**
     * Creates a new instance of AdminManagedBean
     */
    public AdminManagedBean() {
    }
    
    public List<User> getUserList(){
        return ab.getUpToDateUserList();
    }
    
    
    public String removeUser(){
        String username = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("username");
        //System.out.println(username);
        ab.removeUser(username);
        return null;
    }
    
    public String toUser(){
        String username = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("username");
        //System.out.println(username);
        ab.promoteUserToAdmin(username);
        return null;
    }
    
    public String toAdmin(){
        String username = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("username");
        //System.out.println(username);
        ab.disrateAdminToUser(username);
        return null;
    }
}
